#include "actor.h"
#include "scene.h"
#include "../stats/stats.h"
#include "../affiliate/affiliate_bar.h"

void actor::update(float dt)
{
    world::update(dt);
    updateHpBar();
}

void actor::move(float dt)
{
    setWorldPosition(world_position + speed_ * dt);
    world_position = glm::clamp(world_position,glm::vec2(0.0f),game_.getCurrentScene()->getWorldSize());
}

void actor::takeDamage(float damage)
{
    if (!stats_) return;
    stats_->takeDamage(damage);
}

void actor::updateHpBar()
{
    if(!stats_ || !hpBar) return;
    hpBar->setPercent(stats_->getHp() / stats_->getMaxHp());
}
